package cn.uniquetech.hky;

public class GenServiceUtil {
	// service 生成接口
	private static String parseServiceInterface(String tableName, String tableRemarks) {
		String servicePackage = GenerateCodeMysql.PACKAGENAME + ".service";
		StringBuffer sb = new StringBuffer();
		sb.append("package " + servicePackage + ";\r\n");
		String clazz = tableName;
		sb.append("import " + GenerateCodeMysql.PACKAGENAME + ".service.base.IBaseService;\r\n");
		sb.append("import " + GenerateCodeMysql.PACKAGENAME + ".vo." + clazz + "VO;\r\n");
		sb.append("/**" + "\r\n");
		sb.append("* @创建人名 " + GenerateCodeMysql.cjrName + "\r\n");
		sb.append("* @创建日期 " + DateUtil.curDateTime() + "\r\n");
		sb.append("* @文件描述 " + tableRemarks + "service接口\r\n");
		sb.append(" */" + "\r\n");
		sb.append("\r\npublic interface I" + clazz + "Service extends IBaseService<" + clazz + "VO>" + "{\r\n\r\n");
		sb.append("}\r\n");
		FileUtil.writeFile(servicePackage, "I" + clazz + "Service.java", sb.toString());
		return sb.toString();
	}

	// service 生成实现类
	private static String parseServiceClass(String tableName, String tableRemarks) {
		String servicePackage = GenerateCodeMysql.PACKAGENAME + ".service.impl";
		StringBuffer sb = new StringBuffer();
		sb.append("package " + servicePackage + ";\r\n\r\n");
		String clazz = tableName;
		sb.append("import org.springframework.stereotype.Service;\r\n");
		sb.append("import " + GenerateCodeMysql.PACKAGENAME + ".service.I" + clazz + "Service;\r\n");
		sb.append("import " + GenerateCodeMysql.PACKAGENAME + ".mapper." + clazz + "Mapper;\r\n");
		sb.append("import " + GenerateCodeMysql.PACKAGENAME + ".service.base.BaseServiceImpl;\r\n");
		sb.append("import " + GenerateCodeMysql.PACKAGENAME + ".vo." + clazz + "VO;\r\n");

		sb.append("\r\n\r\n");

		sb.append("/**" + "\r\n");
		sb.append("* @创建人名 " + GenerateCodeMysql.cjrName + "\r\n");
		sb.append("* @创建日期 " + DateUtil.curDateTime() + "\r\n");
		sb.append("* @文件描述 " + tableRemarks + "service接口实现类\r\n");
		sb.append(" */" + "\r\n");

		sb.append("@Service\r\n");
		sb.append("@SuppressWarnings(\"unused\")\r\n");
		sb.append("public class " + clazz + "ServiceImpl extends BaseServiceImpl<" + clazz + "VO> implements I" + clazz + "Service" + " {\r\n\r\n");
		String lowMapper = clazz.toLowerCase();
		sb.append("\tprivate " + clazz + "Mapper " + lowMapper + "Mapper;\r\n");
		sb.append("\tpublic " + clazz + "ServiceImpl(" + clazz + "Mapper " + lowMapper + "Mapper) {\r\n");
		sb.append("\t\tsuper();\r\n");

		sb.append("\t\tthis.baseMapper = " + lowMapper + "Mapper;\r\n");
		sb.append("\t\tthis." + lowMapper + "Mapper = " + lowMapper + "Mapper;\r\n");

		sb.append("\t}\r\n");
		sb.append("}\r\n");
		FileUtil.writeFile(servicePackage, clazz + "ServiceImpl.java", sb.toString());
		return sb.toString();
	}

	public static String parseService(String tableName, String tableRemarks) {
		String str = parseServiceInterface(tableName, tableRemarks);
		str = parseServiceClass(tableName, tableRemarks);
		return str;
	}
}
